export function getCurrentTime(fields = 's',time=null) {
	const date = time?new Date(time):new Date();
	let str = '';
	let y = date.getFullYear().toString();
	let m = (date.getMonth() + 1).toString();
	m = m.length == 1 ? '0' + m : m
	let d = date.getDate().toString();
	d = d.length == 1 ? '0' + d : d
	let h = date.getHours().toString();
	h = h.length == 1 ? '0' + h : h
	let i = date.getMinutes().toString();
	i = i.length == 1 ? '0' + i : i
	let s = date.getSeconds().toString();
	s = s.length == 1 ? '0' + s : s
	if (fields == 'y') {
		str = y;
	}
	if (fields == 'm') {
		str = y + '-' + m
	}
	if (fields == 'd') {
		str = y + '-' + m + '-' + d
	}
	if (fields == 'h') {
		str = y + '-' + m + '-' + d + ' ' + h
	}
	if (fields == 'i') {
		str = y + '-' + m + '-' + d + ' ' + h + ':' + i
	}
	if (fields == 's') {
		str = y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s
	}
	return str;
}
export function tsToTime(timestamp,relative=false) {
	if (typeof timestamp === 'string') {
		timestamp = Number(timestamp);
	}
	timestamp*=1000
	if (typeof timestamp !== 'number') {
		alert("输入参数无法识别为时间戳");
	}
	let date = new Date(timestamp);
	let Y = date.getFullYear() + '年';
	let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '月';
	let D = date.getDate().toString();
	D = D.length == 1 ? '0' + D : D
	D = D+'日 '
	let h = date.getHours().toString();
	h = h.length == 1 ? '0' + h : h
	h=h+':'
	let m = date.getMinutes().toString();
	m = m.length == 1 ? '0' + m : m
	m=m + ':'
	let s = date.getSeconds().toString();
	s = s.length == 1 ? '0' + s : s
	return Y + M + D + h + m + s;
}